package com.exam.controller;

import com.google.code.kaptcha.Producer;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/email")
public class EmailController {
    public static final String EMAIL_EXCHANGE_NAME = "email_send_exchange";
    public static final String EMAIL_ROUTING_KEY = "email_routing_key";


    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送邮件消息到RabbitMQ 路由地址为email_routing_key
     *
     * @param email   收件人邮箱地址
     * @param title   邮件标题
     * @param content 邮件内容
     * @return 返回操作结果
     */
    @RequestMapping("/sendEmail")
    public String sendEmail(String email, String title, String content) {
        Map<String, String> infoMap = new HashMap<>();
        infoMap.put("email", email);
        infoMap.put("title", title);
        infoMap.put("content", content);
        rabbitTemplate.convertAndSend(EMAIL_EXCHANGE_NAME, EMAIL_ROUTING_KEY, infoMap);
        return "success";
    }
}
